import { Router } from 'express';
import * as PostsController from '../controllers/posts';
import { isUser, isAdmin } from '@src/util/auth';
import upload from '@src/util/multer';



const router = Router();

// 添加文章 - 需要管理员
router.post('/add', isAdmin, upload.single('thumbimage'), PostsController.updateOrCreatePost);

// 修改文章 - 需要管理员
router.post('/edit', upload.single('thumbimage'), PostsController.updateOrCreatePost);

// 删除文章 - 需要管理员
router.get('/delete/:id', PostsController.deleteOnePost);

// 添加评论 - 需要普通用户
router.post('/addcomment', isUser, PostsController.createComment)

export default router;
